using B.S.Data.MES.API.Applications.BaseData.Command.MaterialTypeCommand;
using B.S.Domain.BasicData.MaterialManagement.Material_type;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.BaseData.CommandHandlers.MaterialTypeCommandHandlers
{
    public class QueryMaterialTypeCommandHandler : IRequestHandler<QueryMaterialTypeCommand, APIRequst<List<Material_type>>>
    {
        private readonly IBaseRepository<Material_type> _materialTypeRepository;

        public QueryMaterialTypeCommandHandler(IBaseRepository<Material_type> materialTypeRepository)
        {
            _materialTypeRepository = materialTypeRepository;
        }

        public Task<APIRequst<List<Material_type>>> Handle(QueryMaterialTypeCommand request, CancellationToken cancellationToken)
        {
            var query = _materialTypeRepository.GetAll();
            return Task.FromResult(new APIRequst<List<Material_type>>
            {
                Code = RequstCode.成功,
                Msg = RequstCode.成功.ToString(),
                Data = query.ToList()
            });
        }
    }
}